<!doctype html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
    <meta name="msapplication-TileColor" content="#206bc4"/>
    <meta name="theme-color" content="#206bc4"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="mobile-web-app-capable" content="yes"/>
    <meta name="HandheldFriendly" content="True"/>
    <meta name="MobileOptimized" content="320"/>
    <meta name="robots" content="noindex,nofollow,noarchive"/>
    <link rel="icon" href="./favicon.ico" type="image/x-icon"/>
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon"/>
    <!-- CSS files -->
    <link href="/dist/css/tabler.min.css" rel="stylesheet"/>
    <link href="/dist/css/demo.min.css" rel="stylesheet"/>
    <link href="https://cdn.bootcdn.net/ajax/libs/zTree.v3/3.5.01/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
    <link href="/dist/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <style>
        body {
            display: none;
        }
    </style>
</head>
<body class="antialiased">
<div class="page">
    <div class="content">
        <div class="container-xl">
            <div class="row">
                <div class="col-12">
                    <div class="row" style="padding: 20px">
                        <div class="card-body">
                            <form>
                                <div class="form-group mb-3 ">
                                    <label class="form-label">头像</label>
                                    <div th:switch="${user.avatar == '' or user.avatar == null}">
                                        <span class="avatar avatar-lg" th:case="true"><svg
                                                xmlns="http://www.w3.org/2000/svg" class="icon icon-md" width="24"
                                                height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"
                                                fill="none" stroke-linecap="round" stroke-linejoin="round"><path
                                                stroke="none" d="M0 0h24v24H0z"></path><circle cx="12" cy="7"
                                                                                               r="4"></circle><path
                                                d="M5.5 21v-2a4 4 0 0 1 4 -4h5a4 4 0 0 1 4 4v2"></path></svg></span>
                                        <span class="avatar avatar-lg" th:case="false"
                                              th:style="'background-image:url('+${user.avatar}+')'"></span>
                                        <button type="button" class="btn btn-info btn-sm avatarUpload">更换头像</button>
                                        <input type="file" class="btn btn-info btn-sm avatarChoose"
                                               style="display: none"></input>
                                    </div>
                                </div>
                                <div class="form-group mb-3">
                                    <label class="form-label">用户名</label>
                                    <div>
                                        <input type="text" class="form-control username" th:value="${user.userName}">
                                    </div>
                                </div>
                                <div class="form-group mb-3">
                                    <label class="form-label">账户名</label>
                                    <input type="text" class="form-control account" th:value="${user.account}">
                                </div>

                                <div class="form-group mb-3">
                                    <label class="form-label">密码</label>
                                    <input type="password" class="form-control pwd">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="form-label">电子邮箱</label>
                                    <div>
                                        <input type="text" class="form-control mail" th:value="${user.eMail}">
                                    </div>
                                </div>
                                <div class="form-group mb-3">
                                    <div class="form-label">状态</div>
                                    <div class="form-check-inline">
                                        <label class="form-check form-check-inline">
                                            <input class="form-check-input delStstus" type="radio" value="false"
                                                   name="userDel" th:checked="${user.isDelete == false}"/>
                                            <span class="form-check-label">有效</span>
                                        </label>
                                        <label class="form-check form-check-inline">
                                            <input class="form-check-input status" type="radio" value="true"
                                                   name="userDel" th:checked="${user.isDelete == true}"/>
                                            <span class="form-check-label">失效</span>
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group mb-3">
                                    <div class="form-label">是否启用</div>
                                    <div class="form-check-inline">
                                        <label class="form-check form-check-inline">
                                            <input class="form-check-input status" type="radio" value="false"
                                                   name="userStatus" th:checked="${user.enable == false}"/>
                                            <span class="form-check-label">启用</span>
                                        </label>
                                        <label class="form-check form-check-inline">
                                            <input class="form-check-input status" type="radio" value="true"
                                                   name="userStatus" th:checked="${user.enable == true}"/>
                                            <span class="form-check-label">冻结</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="form-footer">
                                    <button type="button" class="btn btn-primary formCommit">提交</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<!-- Libs JS -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="/dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/zTree.v3/3.5.01/js/jquery.ztree.all.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js"></script>
<!-- Tabler Core -->
<script src="/dist/js/tabler.min.js"></script>
<!--<script src="/dist/js/user/updateUser.js"></script>-->
<script>
    document.body.style.display = "block";
    var userid = '[[${user.id}]]';
    // 头像上传
    $('.avatarUpload').click(function () {
        $('.avatarChoose').click();
    });
    // 保存
    $('.formCommit').click(function () {
        var data = {
            'id': userid,
            'userName': $(".username").val(),
            'account': $(".account").val(),
            'password': $(".pwd").val().replace(/\s*/g,""),
            'isDelete': $("input[name='userDel']:checked").val(),
            'enable': $("input[name='userStatus']:checked").val(),
            // 'avatar': '',
            'eMail': $(".mail").val()
        }
        alert(JSON.stringify(data))
        $.ajax({
            type: 'POST',
            url: '/userInfo/updateUer',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                if (1 == res.code) {
                    window.parent.location.reload();
                }
            }, error: function () {
                layer.msg('失败');
            }
        });
    });

</script>
</body>
</html>
